#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

pthread_mutex_t g_lock1;

pthread_mutex_t g_lock2;

void* MypthreadStartA(void* arg)
{
    (void)arg;
   //获得锁1
   pthread_mutex_lock(&g_lock1);
   sleep(3);
   //获得锁2
   pthread_mutex_lock(&g_lock2);
   return NULL;
}

void* MypthreadStartB(void* arg)
{
    (void)arg;
    //获得锁2
    pthread_mutex_lock(&g_lock2);
    sleep(3);
    //获得锁1
    pthread_mutex_lock(&g_lock1);
    return NULL;
}
int main()
{
    //初始化锁
    pthread_mutex_init(&g_lock1,NULL);
    pthread_mutex_init(&g_lock2,NULL);
    pthread_t pid;
    pthread_create(&pid,NULL,MypthreadStartA,NULL);
    pthread_create(&pid,NULL,MypthreadStartB,NULL);
    while(1)
    {

    }
    return 0;
}
